package cn.bisoft.java.util.common;

public class EncodeUtil {
	// "gb2312"到"Unicode"的转码
	public static String toUnicode(String str) {
		char[] arChar = str.toCharArray();
		int iValue = 0;
		String uStr = "";
		for (int i = 0; i < arChar.length; i++) {
			iValue = (int) str.charAt(i);
			if (iValue <= 256) {
				// uStr+="&#x00"+Integer.toHexString(iValue)+";";
				uStr += "\\u00" + Integer.toHexString(iValue);
			} else {
				// uStr+="&#x"+Integer.toHexString(iValue)+";";
				uStr += "\\u" + Integer.toHexString(iValue);
			}
		}
		return uStr;
	}

	// "gb2312"到"ISO-8859-1"的转码
	public static String iso2gb(String str) {
		try {
			str = new String(str.getBytes("ISO-8859-1"), "gb2312");
		} catch (Exception e) {
			System.out.println("Encoding Error!");
		}
		return str;
	}

	// "ISO-8859-1"到"gb2312"的转码
	public static String gb2iso(String str) {
		try {
			str = new String(str.getBytes("gb2312"), "ISO-8859-1");
		} catch (Exception e) {
			System.out.println("Encoding Error!");
		}
		return str;
	}

	public static String getChinese(String InputString) throws Exception {
		byte b[] = InputString.getBytes("ISO-8859-1");
		String OutputString = new String(b);
		return OutputString;
	}

}
